﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DSS_XNA.Engine.Error;

namespace DSS_XNA.Engine.Menu
{
    public class MenuOption
    {
        #region Properties

        public string Text
        {
            get { return _text; }
            set { _text = value; }
        }
        private string _text = String.Empty;

        public string Action
        {
            get { return _action; }
            set { _action = value; }
        }
        private string _action = String.Empty;

        public string ActionName
        {
            get { return _actionName; }
            set { _actionName = value; }
        }
        private string _actionName = String.Empty;

        public bool IsSelected
        {
            get { return _isSelected; }
            set { _isSelected = value; }
        }
        private bool _isSelected = false;

        #endregion

        #region Public Methods

        public MenuOption(string text, string action, string actionName, bool isSelected)
        {
            if (text == null)
                throw new DSSException("'text' is null.");
            if (text.Length == 0)
                throw new DSSException("'text' is zero-length.");
            if (action == null)
                throw new DSSException("'action' is null.");
            if (action.Length == 0)
                throw new DSSException("'action' is zero-length.");
            if (actionName == null)
                throw new DSSException("'actionName' is null.");
            if (actionName.Length == 0)
                throw new DSSException("'actionName' is zero-length.");

            this.Text = text;
            this.Action = action;
            this.ActionName = actionName;
            this.IsSelected = isSelected;
        }

        public void RunAction()
        {
            string action = this.Action.ToLower().Trim();

            if (action == "newmenu")
            {
            }
            else if(action == "scriptfile")
            {
                string path = String.Format("scripts\\{0}.spt", this.ActionName);
                Game1.ScriptManager.LoadScriptRequest(path);
            }
            else if (action == "script")
            {
                Game1.ScriptManager.RunCommandRequest(this.ActionName);
            }
            else
            {
                throw new DSSException(String.Format("Unknown menu option action: {0}",
                    this.Action));
            }
        }

        #endregion
    }
}